package com.ktmall.controller;

import com.ktmall.pojo.GoodsItem;
import com.ktmall.pojo.Page;
import com.ktmall.service.GoodsItemService;
import com.ktmall.utils.RespMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/uni/home/goods/guessLike")
@Api(tags = "猜你喜欢相关接口")
public class GoodsItemController {
    private RespMsg respMsg;

    @Autowired
    private GoodsItemService goodsItemService;
    @ApiOperation("查询猜你喜欢列表")
    @RequestMapping("/list")
    public RespMsg getGoodsListPage(@RequestParam(value = "currPageNo" , defaultValue = "1")Integer pageNo,
                                    @RequestParam(value = "pageSize" , defaultValue = "6")Integer pageSize){
        int count = goodsItemService.count();
        Page<GoodsItem> page = new Page<>();
        page.setPageSize(pageSize);
        page.setTotalCount(count);
        page.setCurrPageNo(pageNo);
        List<GoodsItem> list = goodsItemService.getGoodsListPage(page.getCurrPageNo(), page.getPageSize());
        page.setList(list);

        return RespMsg.success("猜你喜欢的商品列表加载成功!",page);
    }

    @PostMapping("/buyNow")
    public RespMsg buyNow(@RequestBody Map<String,Integer> map){
        return RespMsg.success("立即购买",goodsItemService.buyNow(map.get("userId"),map.get("skuId"),map.get("goodsCount")));
    }
}
